//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    baseImg: 'http://a.hiphotos.baidu.com/image/pic/item/728da9773912b31b38b68ca38b18367adbb4e166.jpg',
    imgUrls: []
  },
  onShow() {
    if (app.globalData.openid) {
      this.getIndexSwiper()
    } else {
      this.getUserInfo()
    }
  },
  getIndexSwiper() {
    app.$http('/banners').then(response => {
      this.setData({
        imgUrls: response
      })
    }, error => {})
  },
  getUserInfo() {
    // 调用登录接口,get openID
    wx.showLoading({
      title: '获取用户信息',
      mask: true
    })
    wx.login({
      success: res => {
        app.$http('/token', {
          code: res.code
        }).then(response => {
          app.globalData.openid = response.token
          app.globalData.is_bind = response.is_bind
          this.getIndexSwiper()
        })
      }
    })
  },
  navigateTo(e) {
    if (app.globalData.is_bind) {
      wx.navigateTo({
        url: e.target.dataset.url
      })
    } else {
      wx.navigateTo({
        url: '../member/bindPhone'
      })
    }
  },
  openImgWeb(e) {
    if (e.target.dataset.genre == 'video') {
      wx.navigateTo({
        url: '../index/videoView?url=' + e.target.dataset.link
      })
    } else {
      wx.navigateTo({
        url: '../index/webView?url=' + e.target.dataset.link
      })
    }

  }
})
